/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package spatialmarketplace.cem.action;

import java.util.ArrayList;
import net.sourceforge.stripes.util.Log;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import spatialmarketplace.cem.dao.implementation.UserDaoImpl;
import spatialmarketplace.cem.model.User;

/**
 * This action bean takes care of initializing user session data for the rest of
 * the application to use.
 *
 * */
public class LoginSimulationActionBean extends BaseActionBean {

    private static final Log logger = Log.getInstance(LoginSimulationActionBean.class);
    private static final String FORM = "/WEB-INF/jsp/login.jsp";
    private ArrayList<User> users;
    private static UserDaoImpl userDao = new UserDaoImpl();
    

    @DefaultHandler
    public Resolution form() {
        loadUsers();
        return new ForwardResolution(FORM);
    }

    /*
     * Call this method to load the initial information of the resource to
     * display.
     */
    protected void loadUsers() {

        users = getUserDao().readUsers();
        System.out.println("ArrayList size after readUsers: " + users.size());

    }

    

    public Resolution updateUser() {
        Integer usId = Integer.valueOf(getContext().getRequest().getParameter("newUserId"));
        System.out.println("id new user: " + usId);
        getContext().setCurrentUser(usId);


        return new RedirectResolution(LoginSimulationActionBean.class);
    }

    public static UserDaoImpl getUserDao() {
        return userDao;
    }

    public static void setUserDao(UserDaoImpl userDao) {
        LoginSimulationActionBean.userDao = userDao;
    }

    public ArrayList<User> getUsers() {
        return users;
    }

    public void setUsers(ArrayList<User> users) {
        this.users = users;
    }

    
}
